package routes

import (
	"lottery/bootstrap"
	"lottery/web/blue/bluebell/logger"
	"lottery/web/blue/bluebell/middleware"
)

//import (
//	"bluebell/logger"
//	"bluebell/middleware"
//	"lottery/bootstrap"
//	"net/http"
//
//	"github.com/gin-gonic/gin"
//)

func Setup(app *bootstrap.Bootstrapper) {
	// 发行模式，gin不会打印debug日志。
	//gin.SetMode(gin.ReleaseMode)
	// 注册自己的中间件
	//config := cors.DefaultConfig()
	//config.AllowOrigins = []string{"http://127.0.0.1:8011"}
	//config := cors.New(cors.Config{
	//	AllowOrigins:     []string{"*"},
	//	AllowMethods:     []string{"PUT", "PATCH", "POST", "GET"},
	//	AllowHeaders:     []string{"Origin", "Authorization", "Content-Type", "Access-Control-Allow-Origin"},
	//	ExposeHeaders:    []string{"Content-Length", "Content-Type", "Access-Control-Allow-Origin"},
	//	AllowCredentials: true,
	//	AllowOriginFunc: func(origin string) bool {
	//		return true
	//	},
	//	MaxAge: 24 * time.Hour,
	//})

	// 1. 网站首页
	root := app.Group("bluebell")
	root.Use(logger.GinLogger(), logger.GinRecovery(true))

	root.Use(middleware.Cors())
	v1 := root.Group("/")
	addIndexRouters(v1)
	// 2. 帖子相关接口, 并加载认证中间件
	v2 := root.Group("/pos/")
	v2.Use(middleware.JWTAuthMiddleware())
	addPosRouters(v2)
	// 3. 投票相关接口
	v3 := root.Group("/vote")
	v3.Use(middleware.JWTAuthMiddleware())
	addVoteRouters(v3)
	//return app
}
